<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/21 0021
 * Time: 13:13
 */

namespace App\Services;


use App\Models\AdminMenu;
use TijsVerkoyen\CssToInlineStyles\Exception;

class AdminMenuService
{
    use Singleton;

    /**
     * 构造方法
     * AdminMenuService constructor.
     */
    public function __construct()
    {

    }

    public function getList($root_id = 1, $hasSelf = false)
    {
        $root = AdminMenu::find($root_id);
        if(!$root){
            throw new \Exception('节点不存在！', 404);
        }
        $menuTree = $root->getDescendants()->toHierarchy()->toArray();
        return $menuTree;
    }
}